<?php

use common\models\Ad\AdPosition;
use common\models\Ad\AdPositionSearch;
use common\models\Ad\Ad;
use common\models\Ad\AdSearch;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\file\FileInput;//图片上传
use yii\helpers\ArrayHelper;
use dosamigos\datetimepicker\DateTimePicker;//时间
/* @var $this yii\web\View */
/* @var $model common\models\Ad\Ad */
/* @var $form yii\widgets\ActiveForm */
$guanggw = ArrayHelper::map(AdPosition::find()->all(), 'position_id', 'position_name');
?>
<style>
 .kv-file-content img{ width: 100%!important; }
 </style>
<div class="ad-form">
    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'],'id'=>'subform']); ?>
    <?= $form->field($model, 'position_id')->dropdownlist($guanggw) ?>
    <?= $form->field($model, 'media_type')->dropDownList(array('图片'=>'图片')) ?>
    <?= $form->field($model, 'ad_name')->textInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'ad_link')->textInput(['maxlength' => true]) ?>
	<?php
            if(isset(json_decode($model->ad_code)->newname)){
                $img = json_decode($model->ad_code)->newname;
            }else{
                $img = $model->ad_code;
            }
            $siteRoot = Yii::$app->params['qtimg'];
            echo '<label class="control-label">照片(格式:98**98,以像在图片中部的半身像为佳)</label>;';
            echo FileInput::widget([
                'model' => $model,
                'attribute' => 'ad_code',
                'options' => ['accept' => 'image/*'],
                'pluginOptions' => [
                    'uploadExtraData' => [
                        'album_id' => 20,
                        'cat_id' => 'Nature'
                    ],
                    'initialPreview'=>[
                        !empty($img)?Html::img(Yii::$app->params['qtimg'].$img):null,
                    ],
                    'initialCaption'=> $img,
                    'maxFileCount' => 10,
                    "showUpload"=> false,
                ]
            ]);
            ?>	
	<div>
        <div class="form-group field-classteam-starttime required" style="width: 300px">
            <label class="control-label" for="classteam-starttime">开始时间</label>
            <?= DateTimePicker::widget([
                'model' => $model,
                'attribute' => 'start_time',
                'language' => 'zh-CN',
                'size' => 'ms',
                'clientOptions' => [
                    'autoclose' => true,
                    'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                    'todayBtn' => true
                ]
            ]);?>
        </div>
    </div>
	<div>
        <div class="form-group field-classteam-starttime required" style="width: 300px">
            <label class="control-label" for="classteam-starttime">结束时间</label>
            <?= DateTimePicker::widget([
                'model' => $model,
                'attribute' => 'end_time',
                'language' => 'zh-CN',
                'size' => 'ms',
                'clientOptions' => [
                    'autoclose' => true,
                    'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                    'todayBtn' => true
                ]
            ]);?>
        </div>
    </div>
    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>
    <?php ActiveForm::end(); ?>
</div>
